package cn.wolfcode.education.web.controller;

import cn.wolfcode.education.anno.PermissionName;
import cn.wolfcode.education.query.QueryObject;
import cn.wolfcode.education.service.IClientService;
import cn.wolfcode.education.util.JSONResult;
import cn.wolfcode.education.util.PageResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/clientPool")
public class ClientPoolController {

    @Autowired
    private IClientService clientService;


    @RequiresPermissions("clientPool:view")
    @PermissionName("潜在客户池查看")
    @RequestMapping("")
    public String list() {
        return "clientPool";
    }

    @RequiresPermissions("clientPool:query")
    @PermissionName("潜在户客列表")
    @RequestMapping("query")
    @ResponseBody
    public PageResult query(QueryObject qo) {
        return clientService.queryClientPool(qo);
    }

    @RequiresPermissions("clientPool:receive")
    @PermissionName("接手潜在客户")
    @RequestMapping("receive")
    @ResponseBody
    public JSONResult receive(Long clientId) {
        JSONResult result = new JSONResult();
        try {
            clientService.receiveClient(clientId);
            return result;
        } catch (Exception e) {
            result.setMsg("程序出现异常,攻城狮捉急修复中");
            return result;
        }
    }

    @RequiresPermissions("clientPool:appoint")
    @PermissionName("指派潜在客户")
    @RequestMapping("appoint")
    @ResponseBody
    public JSONResult appoint(Long id, Long appointWhoId) {
        JSONResult result = new JSONResult();
        try {
            clientService.appointClient(id, appointWhoId); // id为被指派的客户,appointWhoId为被指派的销售人员
            return result;
        } catch (Exception e) {
            result.setMsg("程序出现异常,攻城狮捉急修复中");
            return result;
        }
    }
}
